# 第一版
# 获取单个元素在列表出现的数量


'''
num = 0  # 统计变量出现的次数
def getOne(obj, list):
    each = list[0]
    if len(list) == 1:
        global num  # 作用域的关系  这里必须声明变量num 要不然找不到num变量
        if obj == each:
            num += 1
        return num
    else:
        if obj == each:
            num += 1
        return getOne(obj, list[1:])


a = [1, 12, 122, 3224,  54, 1, 1, 123131, 1, 12324, 1, 1123, 1, 124, 1]
v = getOne(1, a)
print(v)
'''

# 第二版


def getOne(obj, list, num=0):
    each = list[0]
    if len(list) == 1:
        if obj == each:
            num += 1
        return num
    else:
        if obj == each:
            num += 1
        return getOne(obj, list[1:], num)


a = [1, 12, 122, 3224,  54, 1, 1, 123131, 1, 12324, 1, 1123, 1, 124, 1]
v = getOne(1, a)
print(v)
